<template>
	<div class="home">
    <div class="top">
      <div class="top-title">北部湾海鲜超市</div>
    </div>
    <div style="height: 120rpx"></div>
    <div class="banner-box">
      <u-swiper :list="bannerList"  img-mode="scaleToFill" :height="280" @click="clickBanner"></u-swiper>
    </div>
    <div class="tips">
      <div class="tip-item">
        <img src="/static/00.png" alt="">
        <span class="text">免费配送</span>
      </div>
      <div class="tip-item">
        <img src="/static/11.png" alt="">
        <span class="text">晚到必赔</span>
      </div>
      <div class="tip-item">
        <img src="/static/22.png" alt="">
        <span class="text">专业检测</span>
      </div>
      <div class="tip-item">
        <img src="/static/33.png" alt="">
        <span class="text">30分钟达</span>
      </div>
    </div>
    <div class="notice">
      <u-notice-bar :list="noticeList" :speed="100"></u-notice-bar>
    </div>
    <div class="content">
      <div class="menu">
        <u-row gutter="8">
          <u-col span="3" v-for="item in menuList" :key="item.id">
            <div class="menu-item" @click="toCategory(item.id)">
              <img :src="item.image" alt="">
              <div class="menu-name">{{ item.name }}</div>
            </div>
          </u-col>
        </u-row>
      </div>
    </div>
    <div class="content">
      <img @click="toProductList" src="/static/recommend_banner.png" alt="">
    </div>
    <div class="content2">
      <RecommendList />
    </div>
  </div>
</template>

<script>
import RecommendList from "./recommendList.vue";
	export default {
    components: {
      RecommendList,
    },
		data() {
			return {
        bannerList: [],
        noticeList: [
          '北部湾海鲜超市上线了！',
        ],
        recommendList: [

        ],
        menuList: []
			}
		},
    onShow() {
      this.$setCar()
    },
		onLoad() {
      this.$api.bannerList().then(res => {
        this.bannerList = res.map(el => {
          return {
            image: this.$baseUrl + el.image,
            title: el.name,
            ...el
          }
        })
      })
      this.$api.categoryList().then(res => {
        this.menuList = res.map(el => {
          return {
            id: el.id,
            name: el.name,
            image: this.$baseUrl + el.image
          }
        })
      })
		},
		methods: {
      toProductList() {
        uni.navigateTo({
          url: '/pages/goods/list'
        })
      },
      toCategory(id) {
        uni.switchTab({
          url: '/pages/category/category?id=' + id
        })
      },
      clickBanner(e) {
        const link = this.bannerList[e].link
        if (link) {
          uni.navigateTo({
            url: '/pages/webview/webview?url=' + link
          })
        }
      }
		}
	}
</script>

<style lang="scss">
page {
  background: #f5f5f5;
}
.home {
  padding-bottom: 120rpx;
  .top {
    background-repeat: no-repeat;
    background-size: cover;
    width: 100%;
    height: 125rpx;
    position: fixed;
    top: 0;
    z-index: 9;
    background-image: url("@/static/top.png");
    .top-title {
      position:absolute;
      top: 30rpx;
      width: 100%;
      text-align: center;
      font-size: 36rpx;
      color: #FFFFFF;
      font-weight: bold;
    }
  }

  .notice {
    background-color: #fff;
    margin-bottom: 30rpx;
  }
  .tips {
    background-color: #fff;
    padding: 30rpx;
    margin-bottom: 30rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 24rpx;
    color: #8d8e99;
    .tip-item {
      display: flex;
      align-items: center;
      img {
        width: 36rpx;
        height: 36rpx;
      }
      .text {
        margin-left: 20rpx;
      }
    }
  }
  .content2 {
    padding:0 20rpx;
  }
  .content {
    background-color: #ffffff;
    padding: 20rpx;
    margin-bottom: 24rpx;
    img {
      width: 100%;
    }
  }
  .banner-box {
    padding: 0 40rpx;
    height: 280rpx;
    background-repeat: no-repeat;
    background-size: 390px 104px;
    background-image: url('@/static/bottom.png');
  }
    .menu {
      margin: 24rpx;
    }
  .menu-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    img {
      width: 100rpx;
      height: 100rpx;
      border-radius: 50%;
      margin-bottom: 24rpx;
    }
    .menu-name {
      font-size: 26rpx;
      color: #303133;
    }
  }
}
</style>
